1 module unde.lib; 2 3 import derelict.sdl2.sdl; 4 import std.container.dlist; 5 import std.stdio; 6 import std.format; 7 import std.string; 8 import std.process; 9 import std.regex; 10 import std.conv; 11 import std.utf; 12 import core.exception; 13 14 import derelict.sdl2.sdl; 15 16 import unde.global_state; 17 import unde.slash; 18 19 import core.sys.posix.sys.stat; 20 import core.sys.posix.pwd; 21 import core.sys.posix.grp; 22 23 version(Windows) 24 { 25 import core.stdc.time; 26 alias ulong ulong_t; 27 } 28 29 enum DOUBLE_DELAY=750; 30 31 enum PATH_MAX=4096; //from linux/limits.h 32 enum UUID_MAX=36; 33 enum MARKS_PATH_MAX=PATH_MAX+UUID_MAX; 34 35 char[i] to_char_array(int i)(string str) 36 { 37 char[i] ret; 38 size_t l = str.length; 39 if (l > i) l = i; 40 ret[0..l] = str[0..l]; 41 return ret; 42 } 43 44 char[i] to_char_array_z(int i)(string str) 45 { 46 char[i] ret; 47 size_t l = str.length; 48 if (l > i) l = i; 49 ret[0..l] = str[0..l]; 50 ret[l..$] = '\0'; 51 return ret; 52 } 53 54 string from_char_array(const char[] str) 55 { 56 int i; 57 foreach (c; str) 58 { 59 if (c == char.init) break; 60 i++; 61 } 62 return str[0..i].idup(); 63 } 64 65 wstring from_char_array(const wchar[] str) 66 { 67 int i; 68 foreach (c; str) 69 { 70 if (c == wchar.init) break; 71 i++; 72 } 73 return str[0..i].idup(); 74 } 75 76 string strip_error(string str) 77 { 78 return str[str.indexOf(":")+2..$]; 79 } 80 81 size_t 82 mystride(T)(ref T str, size_t pos, size_t len = 0) 83 { 84 /* stride falls with OutOfMemoryError Sometimes 85 on not correct symbols, so we will use our stride */ 86 87 if ((str[pos] & 0b1000_0000) == 0) 88 return 1; 89 90 if (len == 0) len = str.length; 91 92 size_t i; 93 for (i=pos+1; i < len && (str[i] & 0b1100_0000) == 0b1000_0000; i++) 94 { 95 } 96 return i-pos; 97 } 98 99 size_t 100 mystrideBack(T)(ref T str, size_t pos) 101 { 102 try 103 { 104 return str.strideBack(pos); 105 } 106 catch (UnicodeException e) 107 { 108 } 109 catch (UTFException e) 110 { 111 } 112 catch (OutOfMemoryError e) 113 { 114 } 115 return 1; 116 } 117 118 size_t 119 myWalkLength(char[] str) 120 { 121 size_t n = 0; 122 for (size_t i = 0; i < str.length; i+=mystride(str, i)) 123 n++; 124 return n; 125 } 126